package com.zhanglijie.improve.aqs.share;

/**
 * @author zhanglijie
 * @version 1.0
 * @since 1.1.0 2022/10/10 0010 21:38
 */
public class SynchronizedCountDownLatch {
    volatile int state;
    public SynchronizedCountDownLatch(int count){
        this.state = count;
    }

    public synchronized void countDown(){
        this.state = this.state-1;
        if(this.state == 0){
            notifyAll();
        }
    }

    public synchronized void await(){
        while(this.state != 0){
            await();
        }
    }
}
